version 13.1
clear all
set scheme s1mono
set more off

* Set to the working directory in which you save the datafiles and have the
* tabs-figs directory set up

cd "~/Dropbox (Samii-research)/SSR Project/replication-file/"

******
******
******
* NEPAL
******
******
******

use pla-civ-mixed-repdata, clear

drop if mixed == 1
keep if excom == 1

* Summary stats

g age_mi = age
replace age_mi = . if age == 0
label var age_mi "Age"
sutex age_mi inc_date_std education father_ed caste_cat1 caste_cat2 caste_cat3 caste_cat4 caste_cat5 wounded soldiers_killed c_maoistevbw c_stateevbw c_maoistshbw sent_recip sent_pg, digits(2) minmax lab file("tabs-figs/pla-sum.tex") replace

* ranks
tab rank_rev

* squared terms:
g c_maoistevbw_sq = c_maoistevbw^2
g c_stateevbw_sq = c_stateevbw^2
g inc_date_std_sq = inc_date_std^2

la var c_maoistevbw_sq "Local Maoist attacks sq."
la var c_stateevbw_sq "Local state attacks sq."
la var inc_date_std_sq "Years sq."

* interaction
g maoistevXshbw = c_maoistevbw*c_maoistshbw
la var maoistevXshbw "Maoist share X attacks"
 
*******
* Pro-sociality among recruits
*******

* Basic results
twoway (scatter sent_combined inc_date_std, jitter(2) ytitle("Rupees sent in Pay-it-fwd. & PG games")) (lfit sent_combined inc_date_std), legend(off)
graph export "tabs-figs/nep_years_sent.pdf", replace
local conf c_maoistevbw c_stateevbw c_maoistshbw
local covs age i.father_ed i.session i.c_caste i.urban m_age m_caste m_urban
keep if excom==1

* Table 1
log using "tabs-figs/tab-1.txt", text replace
eststo clear
eststo: xi: reg sent_combined inc_date_std, robust
boottest inc_date_std, cluster(session)
scalar p_b = r(p)
estadd scalar p_b_add = p_b
eststo: xi: reg sent_combined inc_date_std  `covs', robust
boottest inc_date_std, cluster(session)
scalar p_b = r(p)
estadd scalar p_b_add = p_b
esttab using "tabs-figs/tab-1.tex", replace b(2) se(2) keep(inc_date_std) scalars("p_b_add Wild cluster bootstrap p-value") l star(* 0.1 ** 0.05 *** 0.01) mtitles("No covars."  "w/ covars.") addnotes("OLS estimates; outcome variable is combined amount sent in games, in rupees." "Wild cluster bootstrap is clustered by 17 laboratory sessions." "One observations dropped because of missing data on father's education.")
log close
* Full model results for appendix
esttab using "tabs-figs/tab-1-full-model.tex", replace b(2) se(2) drop(_Isession_*) scalars("p_b_add Wild cluster bootstrap p-value") l star(* 0.1 ** 0.05 *** 0.01) mtitles("No covars."  "w/ covars.") addnotes("OLS estimates; outcome variable is combined amount sent in games, in rupees." "Wild cluster bootstrap is clustered by 17 laboratory sessions." "One observations dropped because of missing data on father's education.")

* Results for the different games (not in paper)
eststo clear
eststo: xi: reg sent_recip inc_date_std, robust
eststo: xi: reg sent_recip inc_date_std  `covs', robust
eststo: xi: reg sent_pg inc_date_std, robust
eststo: xi: reg sent_pg inc_date_std  `covs', robust
eststo: xi: reg sent_combined inc_date_std, robust
eststo: xi: reg sent_combined inc_date_std  `covs', robust
esttab using "tabs-figs/nep_main_regs.tex", replace b(2) se(2) keep (inc_date_std) l star(* 0.1 ** 0.05 *** 0.01) r2(2) mtitles("Pay-it-fwd."  "Pay-it-fwd. w/ covs."  "Pub. gds."  "Pub. gds. w/ covs." "Combined"  "Comb. w/ covs.")

* For appendix: controlling for levels of violence when joining (selection
* vs. socialization):

eststo clear
eststo: xi: reg sent_recip inc_date_std, robust
eststo: xi: reg sent_recip inc_date_std c_stateevbw c_stateevbw_sq, robust
eststo: xi: reg sent_recip inc_date_std c_stateevbw c_stateevbw_sq c_maoistevbw c_maoistevbw_sq c_maoistshbw maoistevXshbw, robust
eststo: xi: reg sent_recip inc_date_std c_stateevbw c_stateevbw_sq c_maoistevbw c_maoistevbw_sq c_maoistshbw maoistevXshbw `covs', robust
esttab using "tabs-figs/nep_app_recip_conflict.tex", replace b(2) se(2) keep (inc_date_std c_stateevbw c_stateevbw_sq c_maoistevbw c_maoistevbw_sq c_maoistshbw maoistevXshbw) l star(* 0.1 ** 0.05 *** 0.01) r2(2) mtitles("Pay-it-fwd."  "Pay-it-fwd."  "Pay-it-fwd."  "Pay-it-fwd. (w/ covs.)")

eststo clear
eststo: xi: reg sent_pg inc_date_std, robust
eststo: xi: reg sent_pg inc_date_std c_stateevbw c_stateevbw_sq, robust
eststo: xi: reg sent_pg inc_date_std c_stateevbw c_stateevbw_sq c_maoistevbw c_maoistevbw_sq c_maoistshbw maoistevXshbw, robust
eststo: xi: reg sent_pg inc_date_std c_stateevbw c_stateevbw_sq c_maoistevbw c_maoistevbw_sq c_maoistshbw maoistevXshbw `covs', robust
esttab using "tabs-figs/nep_app_pg_conflict.tex", replace b(2) se(2) keep (inc_date_std c_stateevbw c_stateevbw_sq c_maoistevbw c_maoistevbw_sq c_maoistshbw maoistevXshbw) l star(* 0.1 ** 0.05 *** 0.01) r2(2) mtitles("Publ. Good" "Publ. Good" "Publ. Good" "Publ. Good (w/ covs)")

eststo clear
eststo: xi: reg sent_combined inc_date_std, robust
eststo: xi: reg sent_combined inc_date_std c_stateevbw c_stateevbw_sq, robust
eststo: xi: reg sent_combined inc_date_std c_stateevbw c_stateevbw_sq c_maoistevbw c_maoistevbw_sq c_maoistshbw maoistevXshbw, robust
eststo: xi: reg sent_combined inc_date_std c_stateevbw c_stateevbw_sq c_maoistevbw c_maoistevbw_sq c_maoistshbw maoistevXshbw `covs', robust
esttab using "tabs-figs/nep_app_combined_conflict.tex", replace b(2) se(2) keep (inc_date_std c_stateevbw c_stateevbw_sq c_maoistevbw c_maoistevbw_sq c_maoistshbw maoistevXshbw) l star(* 0.1 ** 0.05 *** 0.01) r2(2) mtitles("Combined" "Combined" "Combined" "Combined (w/ covs)")

******
* Wounded
******

twoway scatter  wounded inc_date_std, jitter(2)

eststo clear
eststo: reg wounded inc_date_std, robust
eststo: reg wounded inc_date_std inc_date_std_sq, robust
eststo: xi: reg wounded inc_date_std inc_date_std_sq age i.father_ed i.c_caste i.urban m_age m_caste m_urban, robust
eststo: reg wounded sent_combined inc_date_std, robust
eststo: xi: reg wounded sent_combined inc_date_std age i.father_ed i.c_caste i.urban m_age m_caste m_urban, robust
esttab using "tabs-figs/nep_app_wounded.tex", replace b(2) se(2) keep (inc_date_std inc_date_std_sq) l star(* 0.1 ** 0.05 *** 0.01) r2(2)


*******
* Civilian Placebo Check
*******

use pla-civ-mixed-repdata, clear
drop if mixed == 1

* civ summary stats, for appendix
sutex age education father_ed caste_cat1 caste_cat2 caste_cat3 caste_cat4 caste_cat5 sent_recip sent_pg if excom==0, digits(2)  minmax lab file("tabs-figs/civ-sum.tex") replace

* Using civilians as a placebo to validate idea that war
* recruitment opportunities spread in a manner
* that is orthogonal to prevailing levels of pro-sociality
* (placebo test that checks exclusion restriction):

g timing_war_plot = timing_war
replace timing_war_plot = 2007 if timing_war == 9999
g timing_war_t = timing_war_plot - 2001
reg inc_date_std timing_war_t if excom==1, robust

twoway (scatter sent_combined timing_war_plot if excom==1, jitter(2) title("PLA Soldiers") ytitle("Combined sent in Pay-it-fwd. and PG games") xtitle("Year of recruit start")) (lfit sent_combined timing_war_plot if excom==1), legend(off)
graph save overtimeexc, replace
twoway (scatter sent_combined timing_war_plot if excom==0, jitter(2) title("Civilians") ytitle("Combined sent in Pay-it-fwd. and PG games") xtitle("Year of recruit start")) (lfit sent_combined timing_war_plot if excom==0), legend(off)
graph save overtimeciv, replace
graph combine  overtimeexc.gph  overtimeciv.gph
graph export "tabs-figs/nep_civplacebo.pdf", replace
rm "overtimeexc.gph"
rm "overtimeciv.gph"

* Comparison to civs
local covs age i.father_ed i.c_caste i.urban i.timing_war m_age m_caste m_urban
eststo clear
eststo: xi: reg sent_combined excom, robust
eststo: xi: reg sent_combined excom `covs', robust
esttab using "tabs-figs/nep_app_civ_check.tex", replace b(2) se(2) keep (excom) l star(* 0.1 ** 0.05 *** 0.01) r2(2) mtitles("Combined" "Combined (w/ covs)")


preserve 
keep if excom == 1
replace excom = 0
predict sent_com_imp_civ
sum sent_com_imp_civ
scalar sent_com_imp_civ_s = r(mean)
restore

* Comparison to civilians using excom inc_date_std interaction. Keeping mixed sessions
use pla-civ-mixed-repdata, clear
local covs age i.father_ed i.c_caste i.urban i.timing_war m_age m_caste m_urban
eststo clear
eststo: xi: reg sent_combined excom excomXinc_date_std, robust
eststo: xi: reg sent_combined excom excomXinc_date_std `covs', robust
eststo: xi: reg sent_combined excom excomXinc_date_std if mixed==1, robust
eststo: xi: reg sent_combined excom excomXinc_date_std `covs' if mixed==1, robust
esttab using "tabs-figs/nep_civilian_comparison_mixed_incl.tex", replace b(2) se(2) keep (excom excomXinc_date_std) l star(* 0.1 ** 0.05 *** 0.01) r2(2) mtitles("Combined" "Combined (w/ covs)" "Combined, mixed sessions only" "Combined (w/ covs)mixed sessions only")

*******
* Desertion analysis
*******
use nepal-desertion-repdata.dta, clear

lpoly des_rate   start_date_eng, bwidth(1.5) ci ytitle("") ylabel(0(.2)1) yscale(range(0 1)) jitter(2) title("Desertion rates/cohort") legend(off) note("") xtitle("")
graph save "tabs-figs/g1.gph", replace 
lpoly killedrate start_date_eng, bwidth(1.5) ci ytitle("") ylabel(0(.2)1) yscale(range(0 1)) jitter(2) title("KIA rates/cohort")       legend(off) note("") xtitle("")
graph save "tabs-figs/g2.gph", replace 
graph combine "tabs-figs/g1.gph" "tabs-figs/g2.gph", rows(1)

graph export "tabs-figs/nep-des-kia.pdf", replace

rm "tabs-figs/g1.gph"
rm "tabs-figs/g2.gph"

******
******
******
* End Nepal Analysis
******
******

******
******
* Begin CdI analysis
******
******
******

use cdi-militia-repdata, clear

local mainvars f_army game3_sent game4_sent
local cov1 age b_abidjan father_lit edu Akan Krou Malinke Mande Voltaic Christian Muslim female
local cov2 years_served rankorder combat_num wounded

* Summary statistics


* (Plot for years served < 14 to make graph/relationships clear.
* Results below are shown for both with an without the conditioning on years served < 14.)

twoway scatter game_sent_all years_served ///
  if f_militia==0 & years_served<14, ytitle("CFAs sent in Pay-it-fwd. & PG games") jitter(2) mcolor(black) || ///
  lfit game_sent_all years_served if f_militia ==0 & years_served<14, lpattern(dash) lcolor(black) || ///
  scatter game_sent_all_b years_served if f_militia ==1 & years_served<14, jitter(2) mcolor(gray) ///
  || lfit game_sent_all_b years_served if f_militia==1 & years_served<14, lpattern(solid) lcolor(gray) ///
  legend(label(1 "Army") label(3 "Pro-Gbagbo Militia"))

graph export "tabs-figs/cdi-main.pdf", replace

sutex `cov1' `cov2' game3_sent game4_sent if f_militia==0, digits(2) minmax lab file("tabs-figs/cdi-sag-sum.tex") replace nobs
sutex `cov1' `cov2' game3_sent game4_sent if f_militia==1, digits(2) minmax lab file("tabs-figs/cdi-nsag-sum.tex") replace nobs

*Covariate balance check

eststo clear
foreach var of varlist `cov1' {
eststo: reg `var' f_army, robust
esttab using "tabs-figs/summ_stats_cdi_1.tex", replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) 
}

* Wartime experiences

eststo clear
foreach var of varlist `cov2' {
eststo: reg `var' f_army, robust
esttab using "tabs-figs/summ_stats_cdi_2.tex", replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) 
}

* Lab results

g session = location + date

* Table 2
log using "tabs-figs/tab-2.txt", text replace
eststo clear
eststo:     reg game_sent_all years_served f_armyXyears_served f_army, robust
boottest years_served, cluster(session) ptype(upper) seed(1212)
scalar p_b1 = r(p)
estadd scalar p_b_add1 = p_b1
boottest f_armyXyears_served, cluster(session) ptype(lower) seed(1212)
scalar p_b2 = r(p)
estadd scalar p_b_add2 = p_b2
eststo:     reg game_sent_all years_served f_armyXyears_served f_army `cov1', robust
boottest years_served, cluster(session) ptype(upper) seed(1212)
scalar p_b1 = r(p)
estadd scalar p_b_add1 = p_b1
boottest f_armyXyears_served, cluster(session) ptype(lower) seed(1212)
scalar p_b2 = r(p)
estadd scalar p_b_add2 = p_b2
esttab using "tabs-figs/tab-2.tex", replace b(2) se(2) keep(years_served f_armyXyears_served f_army) scalars("p_b_add1 Wild cluster bootstrap one-sided p-value (NSAG)" "p_b_add_2  Wild cluster bootstrap one-sided p-value (SAG-NSAG)") l nonotes star(* 0.1 ** 0.02) mtitles("No covars."  "w/ covars.") addnotes("One-sided tests: * p <0.05, ** p <0.01" "OLS estimates; outcome variable is combined amount sent in games, in CFA." "Wild cluster bootstrap is clustered by 10 laboratory sessions.")
log close
* Full model results for the appendix
esttab using "tabs-figs/tab-2-full-model.tex", replace b(2) se(2) scalars("p_b_add1 Wild cluster bootstrap one-sided p-value (NSAG)" "p_b_add_2  Wild cluster bootstrap one-sided p-value (SAG-NSAG)") l nonotes star(* 0.1 ** 0.02) mtitles("No covars."  "w/ covars.") addnotes("One-sided tests: * p <0.05, ** p <0.01" "OLS estimates; outcome variable is combined amount sent in games, in CFA." "Wild cluster bootstrap is clustered by 10 laboratory sessions.")

* Showing results for individual games (for interpretation, not in main text)

eststo clear
eststo:     reg game3_sent years_served f_armyXyears_served f_army, robust
eststo:     reg game3_sent years_served f_armyXyears_served f_army `cov1', robust
eststo:     reg game4_sent years_served f_armyXyears_served f_army, robust
eststo:     reg game4_sent years_served f_armyXyears_served f_army `cov1', robust
eststo:     reg game_sent_all years_served f_armyXyears_served f_army, robust
eststo:     reg game_sent_all years_served f_armyXyears_served f_army `cov1', robust
esttab using "tabs-figs/cdi_main_m_2.tex", replace b(2) se(2) keep (years_served f_armyXyears_served f_army) l star(* 0.1 ** 0.05 *** 0.01) r2(2) mtitles("Pay-it-fwd."  "Pay-it-fwd. w/ covs."  "Pub. gds."  "Pub. gds. w/ covs." "Combined"  "Comb. w/ covs.")

eststo clear
eststo: reg wounded years_served f_armyXyears_served f_army, robust
eststo: xi: reg wounded years_served f_armyXyears_served f_army age father_lit i.religion b_abidjan, robust
esttab using "tabs-figs/cdi_app_wounded.tex", replace b(2) se(2) keep (years_served f_armyXyears_served f_army) l star(* 0.1 ** 0.05 *** 0.01) r2(2) mtitles("No. times wounded"  "No. times wounded w/ covs.")

* Conditioning on years_served < 14 (robustness check, not in main text)

keep if years_served < 14

eststo clear
eststo:     reg game_sent_all years_served f_armyXyears_served f_army, robust
boottest years_served, cluster(session) ptype(upper) seed(1212)
scalar p_b1 = r(p)
estadd scalar p_b_add1 = p_b1
boottest f_armyXyears_served, cluster(session) ptype(lower) seed(1212)
scalar p_b2 = r(p)
estadd scalar p_b_add2 = p_b2
eststo:     reg game_sent_all years_served f_armyXyears_served f_army `cov1', robust
boottest years_served, cluster(session) ptype(upper) seed(1212)
scalar p_b1 = r(p)
estadd scalar p_b_add1 = p_b1
boottest f_armyXyears_served, cluster(session) ptype(lower) seed(1212)
scalar p_b2 = r(p)
estadd scalar p_b_add2 = p_b2
esttab using "tabs-figs/tab-2-robust-years-served.tex", replace b(2) se(2) keep(years_served f_armyXyears_served f_army) scalars("p_b_add1 Wild cluster bootstrap one-sided p-value (NSAG)" "p_b_add_2  Wild cluster bootstrap one-sided p-value (SAG-NSAG)") l nonotes star(* 0.1 ** 0.02) mtitles("No covars."  "w/ covars.") addnotes("One-sided tests: * p <0.05, ** p <0.01" "OLS estimates; outcome variable is combined amount sent in games, in CFA." "Wild cluster bootstrap is clustered by 10 laboratory sessions.")

* Desertion analysis (plotted for year served < 14 to make graph/relationships clear)

lpoly desrate start_yr if f_militia==1, bwidth(1.5) ci ytitle("") ylabel(0(.2)1) yscale(range(0 1)) jitter(2) title("NSAG desertion rates/cohort") legend(off) note("") xtitle("")
graph save "tabs-figs/g1.gph", replace 
lpoly desrate start_yr if f_militia==0, bwidth(1.5) ci ytitle("") ylabel(0(.2)1) yscale(range(0 1)) jitter(2) title("SAG  desertion rates/cohort") legend(off) note("") xtitle("")
graph save "tabs-figs/g2.gph", replace 
lpoly killedrate start_yr if f_militia==1, bwidth(1.5) ci ytitle("") ylabel(0(.2)1) yscale(range(0 1)) jitter(2) title("NSAG KIA rates/cohort") legend(off) note("") xtitle("")
graph save "tabs-figs/g3.gph", replace 
lpoly killedrate start_yr if f_militia==0, bwidth(1.5) ci ytitle("") ylabel(0(.2)1) yscale(range(0 1)) jitter(2) title("SAG KIA rates/cohort") legend(off) note("") xtitle("")
graph save "tabs-figs/g4.gph", replace 
graph combine "tabs-figs/g1.gph" "tabs-figs/g2.gph" "tabs-figs/g3.gph" "tabs-figs/g4.gph", rows(2)

graph export "tabs-figs/cdi-des-kia.pdf", replace

rm "tabs-figs/g1.gph"
rm "tabs-figs/g2.gph"
rm "tabs-figs/g3.gph"
rm "tabs-figs/g4.gph"

****
****
****
* End CdI analysis
****
****
****

****
****
****
* Begin Kurdistan/Erbil analysis
****
****
****

use kurdistan-repdata, clear

* We adjusted the pay scales in the games after the first 30% of observations
* because of ceiling effects.  We non-parametrically adjust for this by 
* residualizing with a dummy for whether someone was subject to those
* early pay amounts:

reg game_avg_sc early_payamounts
predict game_avg, resid

* interaction terms
g yrs_servedXjoin_post2003 = yrs_served*join_post2003
g yrs_servedXjoin_post2013 = yrs_served*join_post2013

g ageXjoin_post2003 = age*join_post2003
g ageXjoin_post2013 = age*join_post2013

local covs age ageXjoin_post2003 erbil father_edu

la var yrs_served "Years in mvt."
la var yrs_servedXjoin_post2003 "Post-2003 X years in mvt."
la var yrs_servedXjoin_post2013 "Post-2013 X years in mvt."
la var join_post2003 "Post-2003"
la var join_post2013 "Post-2013"

* Table 3

log using "tabs-figs/tab-3.txt", text replace

eststo clear

eststo:     reg game_avg yrs_served  yrs_servedXjoin_post2003 join_post2003, robust
boottest yrs_served, cluster(session) ptype(upper) seed(1212)
scalar p_b1 = r(p)
estadd scalar p_b_add1 = p_b1
boottest yrs_servedXjoin_post2003, cluster(session) ptype(lower) seed(1212)
scalar p_b2 = r(p)
estadd scalar p_b_add2 = p_b2

eststo:     reg game_avg yrs_served  yrs_servedXjoin_post2003 join_post2003 if join_post2013==0, robust
boottest yrs_served, cluster(session) ptype(upper) seed(1212)
scalar p_b1 = r(p)
estadd scalar p_b_add1 = p_b1
boottest yrs_servedXjoin_post2003, cluster(session) ptype(lower) seed(1212)
scalar p_b2 = r(p)
estadd scalar p_b_add2 = p_b2


eststo:     reg game_avg yrs_served  yrs_servedXjoin_post2003 yrs_servedXjoin_post2013 join_post2003 join_post2013, robust
boottest yrs_served, cluster(session) ptype(upper) seed(1212)
scalar p_b1 = r(p)
estadd scalar p_b_add1 = p_b1
boottest yrs_servedXjoin_post2003, cluster(session) ptype(lower) seed(1212)
scalar p_b2 = r(p)
estadd scalar p_b_add2 = p_b2

esttab using "tabs-figs/tab-3-nocov.tex", replace b(2) se(2) keep(yrs_served  yrs_servedXjoin_post2003 yrs_servedXjoin_post2013 join_post2003 join_post2013) scalars("p_b_add1 Wild cluster bootstrap one-sided p-value (NSAG)" "p_b_add_2  Wild cluster bootstrap one-sided p-value (SAG-NSAG)") l nonotes star(* 0.1 ** 0.02) mtitles("Full sample"  "Pre-2013 only" "Full sample") addnotes("One-sided tests: * p <0.05, ** p <0.01" "OLS estimates; outcome variable is combined amount sent in games, in dinars." "Wild cluster bootstrap is clustered by 17 laboratory sessions.")

eststo clear

eststo: xi: reg game_avg yrs_served  yrs_servedXjoin_post2003 join_post2003 `covs', robust
boottest yrs_served, cluster(session) ptype(upper) seed(1212)
scalar p_b1 = r(p)
estadd scalar p_b_add1 = p_b1
boottest yrs_servedXjoin_post2003, cluster(session) ptype(lower) seed(1212)
scalar p_b2 = r(p)
estadd scalar p_b_add2 = p_b2


eststo: xi: reg game_avg yrs_served  yrs_servedXjoin_post2003 join_post2003 `covs' if join_post2013==0, robust
boottest yrs_served, cluster(session) ptype(upper) seed(1212)
scalar p_b1 = r(p)
estadd scalar p_b_add1 = p_b1
boottest yrs_servedXjoin_post2003, cluster(session) ptype(lower) seed(1212)
scalar p_b2 = r(p)
estadd scalar p_b_add2 = p_b2


eststo: xi: reg game_avg yrs_served  yrs_servedXjoin_post2003 yrs_servedXjoin_post2013 join_post2003 join_post2013 `covs' ageXjoin_post2013, robust
boottest yrs_served, cluster(session) ptype(upper) seed(1212)
scalar p_b1 = r(p)
estadd scalar p_b_add1 = p_b1
boottest yrs_servedXjoin_post2003, cluster(session) ptype(lower) seed(1212)
scalar p_b2 = r(p)
estadd scalar p_b_add2 = p_b2

esttab using "tabs-figs/tab-3-wcovs.tex", replace b(2) se(2) keep(yrs_served  yrs_servedXjoin_post2003 yrs_servedXjoin_post2013 join_post2003 join_post2013) scalars("p_b_add1 Wild cluster bootstrap one-sided p-value (NSAG)" "p_b_add_2  Wild cluster bootstrap one-sided p-value (SAG-NSAG)") l nonotes star(* 0.1 ** 0.02) mtitles("Full sample"  "Pre-2013 only" "Full sample") addnotes("One-sided tests: * p <0.05, ** p <0.01" "OLS estimates; outcome variable is combined amount sent in games, in dinars." "Wild cluster bootstrap is clustered by 17 laboratory sessions.")
log close
* Full model results for appendix
esttab using "tabs-figs/tab-3-wcovs-full-model.tex", replace b(2) se(2) scalars("p_b_add1 Wild cluster bootstrap one-sided p-value (NSAG)" "p_b_add_2  Wild cluster bootstrap one-sided p-value (SAG-NSAG)") l nonotes star(* 0.1 ** 0.02) mtitles("Full sample"  "Pre-2013 only" "Full sample") addnotes("One-sided tests: * p <0.05, ** p <0.01" "OLS estimates; outcome variable is combined amount sent in games, in dinars." "Wild cluster bootstrap is clustered by 17 laboratory sessions.")

* residualize age for the graphs

reg yrs_served join_post2003 join_post2013 age ageXjoin_post2003 ageXjoin_post2013
predict rage_yrs_served, resid
la var rage_yrs_served "Yrs served (resid. age)"
reg game_avg join_post2003 join_post2013 age ageXjoin_post2003 ageXjoin_post2013
predict rage_game_avg, resid
la var rage_game_avg "Avg. sent (resid. age)"

local plot_range yscale(range(-4000 2000)) xscale(range(-20 10))
local plot_range_short yscale(range(-4000 2000)) xscale(range(-10 10))

twoway (scatter rage_game_avg rage_yrs_served if join_pre2003==1, ytitle("Dinars sent in Pay-it-fwd. & PG games")) (lfit rage_game_avg rage_yrs_served if join_pre2003==1), ylabel(-4000(1000)2500) yscale(range(-4000 2500)) title("Pre-2003") legend(off)
graph save "tabs-figs/g1.gph", replace
twoway (scatter rage_game_avg rage_yrs_served if join_2003_2013==1, ytitle("Dinars sent in Pay-it-fwd. & PG games")) (lfit  rage_game_avg rage_yrs_served if join_2003_2013==1),  ylabel(-4000(1000)2500) yscale(range(-4000 2500)) title("2003-2013") legend(off)
graph save "tabs-figs/g2.gph", replace
twoway (scatter rage_game_avg rage_yrs_served if join_post2013==1, ytitle("Dinars sent in Pay-it-fwd. & PG games")) (lfit  rage_game_avg rage_yrs_served if join_post2013==1),  ylabel(-4000(1000)2500) yscale(range(-4000 2500)) title("Post 2013") legend(off)
graph save "tabs-figs/g3.gph", replace
graph combine "tabs-figs/g1.gph" "tabs-figs/g2.gph" "tabs-figs/g3.gph", rows(1)

graph export "tabs-figs/erbil-bothcuts.pdf", replace
rm "tabs-figs/g1.gph"
rm "tabs-figs/g2.gph"
rm "tabs-figs/g3.gph"

twoway (scatter rage_game_avg rage_yrs_served if join_pre2003==1 & abs(rage_yrs_served) < 10, ytitle("Dinars sent in Pay-it-fwd. & PG games")) (lfit rage_game_avg rage_yrs_served if join_pre2003==1 & abs(rage_yrs_served) < 10), ylabel(-4000(1000)2500) yscale(range(-4000 2500)) title("Pre-2003")  legend(off)
graph save "tabs-figs/g1.gph", replace
twoway (scatter rage_game_avg rage_yrs_served if join_2003_2013==1, ytitle("Dinars sent in Pay-it-fwd. & PG games")) (lfit  rage_game_avg rage_yrs_served if join_2003_2013==1), ylabel(-4000(1000)2500) yscale(range(-4000 2500)) title("2003-2013")  legend(off)
graph save "tabs-figs/g2.gph", replace
twoway (scatter rage_game_avg rage_yrs_served if join_pre2003==0 & join_2003_2013==0, ytitle("Dinars sent in Pay-it-fwd. & PG games")) (lfit  rage_game_avg rage_yrs_served if join_pre2003==0 & join_2003_2013==0), ylabel(-4000(1000)2500) yscale(range(-4000 2500)) title("Post 2013")  legend(off)
graph save "tabs-figs/g3.gph", replace
graph combine "tabs-figs/g1.gph" "tabs-figs/g2.gph" "tabs-figs/g3.gph", rows(1)
graph export "tabs-figs/erbil-bothcuts-nooutlier.pdf", replace
rm "tabs-figs/g1.gph"
rm "tabs-figs/g2.gph"
rm "tabs-figs/g3.gph"

* Desertion analysis

lpoly desrate    start_yr, bwidth(1.5) ci ytitle("") ylabel(0(.2).6) yscale(range(-.05 .7)) jitter(1) title("Desertion rates/cohort") legend(off) note("") xtitle("") xli(2003 2014, axis(1))  xla(1965 1975 1985 1995 2003 2005 2014, angle(45)) 
graph save "tabs-figs/g1.gph", replace 
lpoly killedrate start_yr, bwidth(1.5) ci ytitle("") ylabel(0(.2).6) yscale(range(-.05 .7)) jitter(1) title("KIA rates/cohort")       legend(off) note("") xtitle("") xli(2003 2014, axis(1))  xla(1965 1975 1985 1995 2003 2005 2014, angle(45)) 
graph save "tabs-figs/g2.gph", replace 
graph combine "tabs-figs/g1.gph" "tabs-figs/g2.gph", rows(1)

graph export "tabs-figs/erbil-des-kia.pdf", replace

rm "tabs-figs/g1.gph"
rm "tabs-figs/g2.gph"


* summary stats

* for join_pre2003
sutex age erbil edu father_edu yrs_served rankorder father_peshmerga father_iraqi_army times_wounded friend_martyr game3 game4 game_avg if join_pre2003==1, file("tabs-figs/erbil-sum-pre2003.tex") digits(2) minmax replace nobs

* for join bet _2003_2013
sutex age erbil edu father_edu yrs_served rankorder father_peshmerga father_iraqi_army times_wounded friend_martyr game3 game4 game_avg if join_2003_2013==1, file("tabs-figs/erbil-sum-20032013.tex") digits(2) minmax replace nobs

* for join_post2013
sutex age erbil edu father_edu yrs_served rankorder father_peshmerga father_iraqi_army times_wounded friend_martyr game3 game4 game_avg if join_post2013==1, file("tabs-figs/erbil-sum-post2013.tex") digits(2) minmax replace nobs

*Covariate balance check

order age erbil edu father_edu father_peshmerga father_iraqi_army yrs_served rankorder times_wounded friend_martyr 

// bet Pre-2003 and rest
eststo clear
foreach var of varlist age - friend_martyr { 
			eststo: reg `var' join_pre2003,robust
			   esttab using "tabs-figs/join_pre_2003.tex", replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) 
			}

// bet: bet post2003 & pre2013 joiners and rest 
eststo clear
foreach var of varlist age - friend_martyr { 
			eststo: reg `var' join_2003_2013,robust
			   esttab using "tabs-figs/join_2003_2013.tex", replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) 
			}
			

// join_post2013
eststo clear
foreach var of varlist age - friend_martyr { 
			eststo: reg `var' join_post2013,robust
			   esttab using "tabs-figs/join_post2013.tex", replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) 
			}
			
